/*
 * Copyright (C) 2012 by Hao Hou<ghost89413@gmail.com>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>*
 */
#ifndef __LOG_H__
#define __LOG_H__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <errno.h>

#ifndef HAVE_MACRO_FILE
#define __FILE__ "undefined"
#endif

#ifndef HAVE_MACRO_FUNCTION
#define __FUNCTION__ "undefined"
#endif

#ifndef HAVE_MACRO_LINE
#define __LINE__ "undefined"
#endif

#ifndef LOG_LEVEL
#define LOG_LEVEL 6
#endif

typedef enum {
	FATAL,
	ERROR,
	WARNING,
	NOTICE,
	INFO,
	TRACE,
	DEBUG
} ErrorLevel;
void	VineWriteLog(ErrorLevel level, const char* file, 
		     const char* func, int line,
		     const char* fmt , ...);
#define VINE_LOG(el,fmt,arg...) do{\
		VineWriteLog( (el) , __FILE__,__FUNCTION__,__LINE__,fmt,##arg);\
	}while(0)
#if LOG_LEVEL >= 0
#	define VINE_LOG_FATAL(fmt,arg...) VINE_LOG(FATAL,fmt,##arg)
#else
#	define VINE_LOG_FATAL(...)
#endif

#if LOG_LEVEL >= 1
#	define VINE_LOG_ERROR(fmt,arg...) VINE_LOG(ERROR,fmt,##arg)
#else
#	define VINE_LOG_ERROR(...)
#endif

#if LOG_LEVEL >= 2
#	define VINE_LOG_WARNING(fmt,arg...) VINE_LOG(WARNING,fmt,##arg)
#else
#	define VINE_LOG_WARNING(...)
#endif

#if LOG_LEVEL >= 3
#	define VINE_LOG_NOTICE(fmt,arg...) VINE_LOG(NOTICE,fmt,##arg)
#else
#	define VINE_LOG_NOTICE(...)
#endif

#if LOG_LEVEL >= 4
#	define VINE_LOG_INFO(fmt,arg...) VINE_LOG(INFO,fmt,##arg)
#else
#	define VINE_LOG_INFO(...)
#endif

#if LOG_LEVEL >= 5
#	define VINE_LOG_TRACE(fmt,arg...) VINE_LOG(TRACE,fmt,##arg)
#else
#	define VINE_LOG_TRACE(...)
#endif

#if LOG_LEVEL >= 6
#	define VINE_LOG_DEBUG(fmt,arg...) VINE_LOG(DEBUG,fmt,##arg)
#else
#	define VINE_LOG_DEBUG(...)
#endif

#endif
